package com.ljf.spring.filter;

import com.ljf.framework.filter.LjfFilterManager;
import com.ljf.framework.log.LjfLogManager;
import com.ljf.servlet.repeatable.RepeatableFilter;
import org.springframework.core.annotation.Order;

import javax.servlet.*;
import java.io.IOException;

/**
 * Servlet全局过滤器
 */
@Order(-100)
public class LjfServletFilter implements Filter {


    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {

        // 初始化日志
        LjfLogManager.createLjfLogId();
        // 构建可重复度
        request = new RepeatableFilter().doCusFilter(request);

        // 执行拦截器
        boolean continueRun = LjfFilterManager.doLjfFilter();
        if (!continueRun) return;

        // 执行
        chain.doFilter(request, response);
    }

}
